<template>
  <md-field>
    <md-input-item v-model="form.num" type="money" :title="$t('token.transfer_num')"></md-input-item>
    <div style="padding: 20px 40px 0">
      <md-button type="primary" :loading="loading" @click="post" round>{{ $t('confirm') }}</md-button>
      <div style="padding-top: 30px; text-align: center">
        <md-button type="link" icon="address-book" @click="log">{{ $t('token.take_log') }}</md-button>
      </div>
    </div>
  </md-field>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { toast } from '@/style'
import { t } from '@/lang'
import { userInfo } from '@/model/user'
import { withdrawal } from '@/api/user'

const router = useRouter()
const form = ref({})
const loading = ref(false)

const post = () => {
  loading.value = true
  withdrawal(form.value).then(res => {
    toast(t('ok'))
    userInfo()
    log()
  }).catch(err => {
    toast(err.message)
  }).finally(() => {
    loading.value = false
  })
}

const log = () => {
  router.push('/token/take/log')
}

</script>